<script>
import { HiPage, dataHelper, utils } from "hi-ui";
import request from "@/utils/request";
import hiSetting from "@/hiSetting";
export default {
  name: "func",
  componentName: "funcpage",
  mixins: [HiPage],
  beforeRouteEnter(to, from, next) {
    if (to.path.lastIndexOf(".func") != -1) {
      let __viewItemId =
        to.query.__viewItemId ||
        to.matched[to.matched.length - 1].props.default.__viewItemId;
      dataHelper.funcHelper
        .getFuncInfo({
          request: request,
          url: hiSetting.oauth + to.path,
          data: {
            __viewItemId: __viewItemId,
          },
        })
        .then(function (resp) {
          if (resp.status == 200 && to.path != resp.dataPack.path) {
            next(
              `${resp.dataPack.path}.func?__func=${to.path}&__viewItemId=${__viewItemId}`
            );
          } else {
            next();
          }
        });
    } else if (to.path.lastIndexOf(".flow") != -1) {
      var config = {
        fordernumber: to.query.__fnumber,
        request: request,
        url: hiSetting.openOrdernumber,
      };
      dataHelper.flowHelper.openOrdernumber(config).then(function (resp) {
        if (resp.status == 200) {
          next(
            `/${resp.outParamter.task.pcform}.flow${to.fullPath.substring(
              to.fullPath.indexOf("?")
            )}`
          );
        } else {
          next();
        }
      });
    } else {
      next();
    }

    // 在渲染该组件的对应路由被 confirm 前调用
    // 不！能！获取组件实例 `this`
    // 因为当守卫执行前，组件实例还没被创建
  },
  data() {
    return {};
  },

  methods: {
    closepage() {},
  },
  mounted() {},
};
</script>
